package cn.com.jtang.wedding.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.dao.SuggestionDao;
import cn.com.jtang.wedding.model.Suggestion;

public class SuggestionDaoImpl extends BaseDaoImpl implements SuggestionDao {

	private static final String ID = "id";
	private static final String CONTENT = "content";
	private static final String TIME = "time";
	private static final String ADMINUSERID = "adminUserId";
	private static final String REPLY = "Reply";
	private static final String REPLYTIME = "replyTime";
	private static final String ISREPLY = "isReply";
	
	@Override
	public List insertModelToList(Object object) {
		Suggestion suggestion = (Suggestion)object;
		List args = new ArrayList();
		args.add(0);
		args.add(suggestion.getContent());	
		args.add(suggestion.getTime());
		args.add(suggestion.getAdminUserId());	
		args.add(suggestion.getReply());
		args.add(suggestion.getReplyTime());
		args.add(suggestion.getIsReply());
		return args;
	}

	@Override
	public Object resultMapper(ResultSet rs, int rowNum) throws SQLException {
		Suggestion suggestion = new Suggestion();
		suggestion.setId(rs.getLong(ID));
		suggestion.setContent(rs.getString(CONTENT));
		suggestion.setTime(rs.getDate(TIME));
		suggestion.setAdminUserId(rs.getLong(ADMINUSERID));
		suggestion.setReply(rs.getString(REPLY));
		suggestion.setReplyTime(rs.getDate(REPLYTIME));
		suggestion.setIsReply(rs.getInt(ISREPLY));
		return suggestion;
	}

	@Override
	public Map updateModelToMap(Object object) {
		Suggestion suggestion = (Suggestion)object;
		Map map = new HashMap();
		map.put(ID, suggestion.getId());
		map.put(CONTENT, suggestion.getContent());
		map.put(TIME, suggestion.getTime());
		map.put(ADMINUSERID, suggestion.getAdminUserId());
		map.put(REPLY, suggestion.getReply());
		map.put(REPLYTIME, suggestion.getReplyTime());
		map.put(ISREPLY, suggestion.getIsReply());
		return map;
	}
	

	public String insert(Suggestion suggestion){
		return super.insert(suggestion);
	}
	
	public Suggestion queryById(Long id){
		return (Suggestion)super.queryById(id);
	}
	
	public int updateById(Long id, Suggestion suggestion) {
		return super.updateById(id, suggestion);
	}
	
	public int deleteById(Long id) {
		return super.deleteById(id);
	}
	
	public List queryAll(Map<String, Object> map, int start,int end, String... orderByStr){
		return super.queryAll(map, start, end, orderByStr);
	}
}
